home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-21 | 28.9 KB | 1,091 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CActiveXView.cpp ©1996 Microsoft Corporation. All rights reserved.
- // ===========================================================================
- //
- // manages an active x control
-
- #ifdef PowerPlant_PCH
- #include PowerPlant_PCH
- #endif
-
- #include "ActiveXAppConstants.h"
- #include "CActiveXDocument.h"
- #include "CActiveXView.h"
- #include "CActiveXPeriodical.h"
- #include "CArgumentParser.h"
- #include <LArray.h>
- #include <LStream.h>
- #include <UDrawingState.h>
- #ifdef MULTI_CONTEXT_TEST_APP
- #include "CActiveXShadowView.h"
- #endif // MULTI_CONTEXT_TEST_APP
- #include "Util.h"
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #include "HEADERS.H"
- #include "CIdle.h"
-
- static void CToPString(Char8* CPtr, StringPtr PStr);
-
- #pragma mark === CActiveXView::Construction & Destruction ===
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::CreateActiveXViewStream [static]
- // ---------------------------------------------------------------------------
- // Return a new active x object initialized using data from a Stream
-
- CActiveXView*
- CActiveXView::CreateActiveXViewStream(
- LStream *inStream)
- {
- return (new CActiveXView(inStream));
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::CActiveXView
- // ---------------------------------------------------------------------------
- // Default Constructor
-
- CActiveXView::CActiveXView() : LDragAndDrop(UQDGlobals::GetCurrentPort(), this)
- {
- CommonInit();
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::CActiveXView(LStream*)
- // ---------------------------------------------------------------------------
- // Construct control from the data in a Stream
-
- CActiveXView::CActiveXView(LStream *inStream)
- : LView(inStream), LDragAndDrop(UQDGlobals::GetCurrentPort(), this)
- {
- CArgumentParser Parser;
- Char8 **ArgNames;
- Char8 **ArgValues;
- Int16 ArgCount;
- Ptr ArgBufferP;
- Uchar8 CharCount;
-
- CommonInit();
-
- inStream->ReadData(&CharCount, sizeof(Uchar8));
- while (CharCount--)
- {
- Char8 Char;
- inStream->ReadData(&Char, sizeof(Char8));
- Parser.ProcessChar(Char);
- }
- Parser.ProcessChar('\0'); // tell the parser the stream is done
-
- Parser.GetArguments(&ArgBufferP,&ArgNames, &ArgValues, &ArgCount);
-
- if (ArgCount)
- InstantiateControl(ArgNames, ArgValues, ArgCount);
-
- if (ArgBufferP)
- ::DisposePtr(ArgBufferP);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::~CActiveXView()
- // ---------------------------------------------------------------------------
- // Destructor
-
- CActiveXView::~CActiveXView(void)
- {
- RemoveControl();
- while (mViewArrayP && mViewArrayP->GetCount())
- {
- LView *theView;
- mViewArrayP->FetchItemAt(1, (void*)&theView);
- #ifdef MULTI_CONTEXT_TEST_APP
- if (theView != this)
- ((CActiveXShadowView*)theView)->SetMasterView(NULL);
- #endif // MULTI_CONTEXT_TEST_APP
- mViewArrayP->RemoveItemsAt(1,1);
- }
- delete mViewArrayP;
- mViewArrayP = NULL;
- }
-
-
- #pragma mark === CActiveXView ===
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::CommonInit
- // ---------------------------------------------------------------------------
- // do common initialization of the view
-
- void
- CActiveXView::CommonInit(void)
- {
- Boolean8 FalseBool = false;
-
- mStreamIdleP = NULL;
- mMouseUpAttachmentP = NULL;
- mDocumentP = CActiveXDocument::GetDefaultContainer();
- mViewArrayP = new LArray(sizeof(LView *));
- mViewArrayP->InsertItemsAt(1, 1, (void*)&this);
- mPendingViewsP = NULL;
- mActiveView = this;
- mInRequestFocus = false;
- mContextDirty = false;
- mDirty = false;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::InstantiateControl(Char8 **, Char8 **, Int16)
- // ---------------------------------------------------------------------------
- // Instantiate a control when passed in embed style parameters
-
- void
- CActiveXView::InstantiateControl(Char8 **inArgNames, Char8 **inArgValues, Int16 inArgCount)
- {
- // find the height and width parameters and size the pane accordingly
- // pass all parameters through by AddParam
- Boolean8 HasWidth, HasHeight;
- Int16 i;
- PlatformPoint Size;
-
- HasWidth = HasHeight = false;
- for (i = 0; i < inArgCount; i++)
- {
- if (!HasWidth || !HasHeight)
- {
- Boolean8 IsWidth, IsHeight;
- Str255 TempString;
-
- IsWidth = IsHeight = false;
- CToPString(*(inArgNames+i), TempString);
- if (!HasWidth)
- HasWidth = IsWidth = ::EqualString(TempString, "\pWIDTH", false, true);
- if (!HasHeight && !IsWidth)
- HasHeight = IsHeight = ::EqualString(TempString, "\pHEIGHT", false, true);
-
- if (IsHeight || IsWidth)
- {
- Int32 Temp;
- CToPString(*(inArgValues+i), TempString);
- ::StringToNum(TempString, &Temp);
- if (IsHeight)
- Size.v = Temp;
- else
- Size.h = Temp;
- }
- }
-
- this->AddParam(*(inArgNames+i), *(inArgValues+i));
- }
-
- if (HasWidth && HasHeight)
- RequestSizeChange(&Size);
-
- this->CreateControl(true);
- this->SetContainerData((IContainer*) mDocumentP, this);
-
- // add the site to the document
- mDocumentP->AddSite(this);
-
- // if the port exists, then tell the control about the drawing contexts
- AttachPort(mDocumentP->GetPort() != NULL);
-
- // create the streaming idle object
- mStreamIdleP = new CIdle();
- mStreamIdleP->StartIdling();
-
- Refresh();
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::InstantiateControl(FSSpecPtr)
- // ---------------------------------------------------------------------------
- // Instantiate a control when passed in a control's fsspec
-
- void
- CActiveXView::InstantiateControl(FSSpecPtr inFileSpec)
- {
- Boolean8 GotArgs = false;
- Char8 **ArgNames;
- Char8 **ArgValues;
- Int16 ArgCount;
- Ptr ArgBufferP = NULL;
- Int16 ResFile = ::FSpOpenResFile(inFileSpec, fsRdPerm);
- StringHandle StrHandle = NULL;
-
- if (::ResError() == noErr)
- {
- if ((StrHandle = ::GetString(128)) != NULL)
- {
- CArgumentParser Parser;
- Int16 i = 0;
- Int16 Len = **StrHandle;
-
- while (++i <= Len)
- Parser.ProcessChar((*StrHandle)[i]);
- Parser.ProcessChar('\0');
- ::ReleaseResource(Handle(StrHandle));
- GotArgs = Parser.GetArguments(&ArgBufferP,&ArgNames, &ArgValues, &ArgCount);
- }
- ::CloseResFile(ResFile);
- }
-
- // for now we need to close the res file before we instantiate the control
- // so that the resource fork chain is straight forward. I hope to fix this.
-
- if (GotArgs)
- {
- Handle BaseURL;
-
- if ( (BaseURL = FileURLFromFileSpec(inFileSpec)) != NULL )
- {
- ::HLock(BaseURL);
- SetBaseURL(*BaseURL);
- ::HUnlock(BaseURL);
- ::DisposeHandle(BaseURL);
- }
-
- InstantiateControl(ArgNames, ArgValues, ArgCount);
- ::DisposePtr(ArgBufferP);
- }
- else
- ::SysBeep(0);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::RemoveControl()
- // ---------------------------------------------------------------------------
- // Remove the Active X Control from the view
-
- void CActiveXView::RemoveControl(void)
- {
- this->RequestFocus(false, FocusSet(FullFocusSet));
-
- // remove contexts from the control
- {
- Boolean8 FalseBool = false;
- LView *theViewP;
- for (ArrayIndexT i = 1; mViewArrayP->FetchItemAt(i, (void*)&theViewP); i++)
- UpdateDrawingContext(theViewP, RemoveContext);
- }
-
- if (mControlP)
- {
- mDocumentP->RemoveSite(this);
- this->DestroyControl();
- }
-
- if (mMouseUpAttachmentP)
- {
- delete mMouseUpAttachmentP;
- mMouseUpAttachmentP = NULL;
- }
-
- // no control to idle - if it was being idled
- SetIdleTime(RemoveAllIdlers, NULL);
-
- mActiveView = this;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::UpdateDrawingContext
- // ---------------------------------------------------------------------------
- // tell the control about a draw context change
-
- void
- CActiveXView::UpdateDrawingContext(LView *inDrawView, ContextCommand inContextCommand)
- {
- OnContextChange((UInt32) inDrawView->GetPaneID(), inContextCommand);
- }
-
-
- #ifdef MULTI_CONTEXT_TEST_APP
- // ---------------------------------------------------------------------------
- // • CActiveXView::ClickInShadowView
- // ---------------------------------------------------------------------------
- // tell acquire context which view is the 0th one
-
- void
- CActiveXView::ClickInShadowView(CActiveXShadowView* inShadowView, SMouseDownEvent &inMouseDown)
- {
- LView *PrevActiveView = mActiveView;
-
- if ((mActiveView = inShadowView) == NULL)
- mActiveView = this;
-
- if (PrevActiveView != mActiveView)
- {
- if (PrevActiveView)
- UpdateDrawingContext(PrevActiveView, DeactivateContext);
- UpdateDrawingContext(mActiveView, ActivateContext);
- }
-
- HandleClick(inMouseDown);
- }
- #endif // MULTI_CONTEXT_TEST_APP
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::GetContextID
- // ---------------------------------------------------------------------------
- // get an LView from the context id
-
- Boolean8
- CActiveXView::GetContextID(Int32 inContextIndex, Uint32* outContextID)
- {
- LView *theView = NULL;
-
- mViewArrayP->FetchItemAt(inContextIndex, &theView);
-
- if (theView)
- *outContextID = theView->GetPaneID();
-
- return theView != NULL;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::GetDrawingViewFromID
- // ---------------------------------------------------------------------------
- // get an LView from the context id
-
- LView *
- CActiveXView::GetDrawingViewFromID( Uint32 inContextID )
- {
- LView *ResultDrawView = NULL;
- LView *theView = NULL;
-
- for (ArrayIndexT i = 1; !ResultDrawView && mViewArrayP->FetchItemAt(i, (void*)&theView); i++)
- {
- if (theView->GetPaneID() == inContextID)
- ResultDrawView = theView;
- }
-
- return ResultDrawView;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::AcquireContext
- // ---------------------------------------------------------------------------
- // acquire the context of the view passed in
-
- ErrorCode
- CActiveXView::AcquireContext(LView* inView, DrawContext* outContext)
- {
- if (!inView || mHavePort || !mDocumentP->GetPort())
- {
- // Don't allow the object to nest calls to GetDC
- outContext->Port = NULL;
- return E_FAIL;
- }
-
- // Save off the current port state
- {
- GrafPtr SavePort, DrawingPort;
-
- ::GetPort(&SavePort);
- inView->EstablishPort();
- ::GetPort(&DrawingPort);
- ::SetPort(SavePort);
-
- SavePortState(DrawingPort);
- }
-
- // Initialize the port to a known state.
- inView->FocusDraw();
- outContext->PortType = QDWindowPortType;
- outContext->DrawAspect = DVASPECT_CONTENT;
- outContext->ContextID = inView->GetPaneID(); // context id's must be unique throughout the scope
- // of the application. since the shadow views don't
- // come and go we'll just use their pane ids as
- // context ids. If we had dynamic split panes, then
- // this wouldn't work.
- outContext->ContainerRef = Uint32(inView);
- outContext->Port = (GrafPtr) mDocumentP->GetPort();
-
- {
- SDimension32 Size;
- inView->GetImageSize(Size);
- outContext->Location.top = outContext->Location.left = 0;
- outContext->Location.bottom = Size.height;
- outContext->Location.right = Size.width;
- }
- // inView->CalcLocalFrameRect(outContext->Location);
- // ::OffsetRect(&outContext->Location, -outContext->Location.left, -outContext->Location.top);
-
- mHavePort = true;
-
- return S_OK;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::DrawSelf
- // ---------------------------------------------------------------------------
- // Draw the control
-
- void
- CActiveXView::DrawSelf()
- {
- Boolean8 FailedToDraw = true;
-
- if (mControlP)
- {
- DrawContext theDrawContext = {BeginPortType};
-
- if (mPendingViewsP)
- AttachPort(true);
-
- if (mContextDirty)
- {
- UpdateDrawingContext(this, UpdateContext);
- mContextDirty = false;
- }
-
- if (this->AcquireContext(this, &theDrawContext) == S_OK)
- {
- mControlP->Draw(&theDrawContext);
- FailedToDraw = false;
- this->ReleaseContext(&theDrawContext);
- }
- }
-
- if (FailedToDraw)
- {
- Rect Frame;
- StringPtr ErrorMessage = "\pDrop a control here!";
-
- CalcLocalFrameRect(Frame);
- ::PenNormal();
- ::FillRect(&Frame, &UQDGlobals::GetQDGlobals()->ltGray);
-
- ::TextFace(bold);
- ::TextFont(0);
- ::TextSize(12);
- ::TETextBox(ErrorMessage + 1, *ErrorMessage, &Frame, 1);
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::DoEvent
- // ---------------------------------------------------------------------------
- // Pass events to Active X
-
- void
- CActiveXView::DoEvent(EventRecord *Event, Boolean *PassEventUp, Boolean *RemoveAttachment)
- {
- *RemoveAttachment = true;
- *PassEventUp = true;
-
- if (mControlP)
- {
- if (Event->what != mouseUp)
- *RemoveAttachment = false;
- else
- mControlP->DoMouse(MouseUp, Event);
- }
- }
-
-
- #ifdef MULTI_CONTEXT_TEST_APP
- // ---------------------------------------------------------------------------
- // • CActiveXView::AddShadowView
- // ---------------------------------------------------------------------------
- // add a shadow view to the shadow view list
-
- void
- CActiveXView::AddShadowView(CActiveXShadowView *inShadowView)
- {
- Boolean8 FalseBool = false;
-
- mViewArrayP->InsertItemsAt(1, LArray::index_Last, (void*)&inShadowView);
- UpdateDrawingContext(inShadowView, AddContext);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::RemoveShadowView
- // ---------------------------------------------------------------------------
- // add a shadow view to the shadow view list
-
- void
- CActiveXView::RemoveShadowView(CActiveXShadowView *inShadowView)
- {
- long ContextIndex = mViewArrayP->FetchIndexOf(&inShadowView);
-
- UpdateDrawingContext(inShadowView, RemoveContext);
-
- if ( mActiveView == inShadowView )
- mActiveView = this;
-
- mViewArrayP->RemoveItemsAt(1, ContextIndex);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::DrawShadowView
- // ---------------------------------------------------------------------------
- // add a shadow view to the shadow view list
-
- void
- CActiveXView::DrawShadowView(CActiveXShadowView *inShadowView, Boolean8 inUpdateContext)
- {
- Boolean FailedToDraw = true;
- DrawContext theDrawContext = {BeginPortType};
-
- if (mControlP)
- {
- if (mPendingViewsP)
- AttachPort(true);
-
- if (inUpdateContext)
- UpdateDrawingContext(inShadowView, UpdateContext);
-
- if (this->AcquireContext(inShadowView, &theDrawContext) == S_OK)
- {
- mControlP->Draw(&theDrawContext);
- FailedToDraw = false;
- this->ReleaseContext(&theDrawContext);
- }
- }
-
- if (FailedToDraw)
- {
- Rect Frame;
-
- CalcLocalFrameRect(Frame);
- ::PenNormal();
- ::FillRect(&Frame, &UQDGlobals::GetQDGlobals()->ltGray);
- ::FrameRect(&Frame);
- }
- }
- #endif // MULTI_CONTEXT_TEST_APP
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::HandleClick
- // ---------------------------------------------------------------------------
- // pass the event to the control and do local stuff
-
- void
- CActiveXView::HandleClick(SMouseDownEvent &inMouseDown)
- {
- if (mControlP)
- {
- mControlP->DoMouse(MouseDown, &inMouseDown.macEvent);
- EventRecord TempEvent;
-
- // now make the main event loop tell us about the mouse up
- if (::StillDown() || (::EventAvail(mDownMask | mUpMask, &TempEvent) && TempEvent.what == mouseUp))
- {
- LCommander *SuperSuper = this;
- LCommander *Super;
-
- if (!mMouseUpAttachmentP)
- mMouseUpAttachmentP = new CActiveXAttachment(this);
- else if (mMouseUpAttachmentP->GetOwnerHost())
- DebugStr("\pWhat - it is already in use!");
-
- do
- {
- Super = SuperSuper;
- SuperSuper = Super->GetSuperCommander();
- }
- while (SuperSuper);
-
- Super->AddAttachment(mMouseUpAttachmentP, false);
- }
- }
- else
- // clicked in an empty pane - maybe wanting to designate it for insert commands
- BeTarget();
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::AttachPort
- // ---------------------------------------------------------------------------
- // pass the event to the control and do local stuff
-
- void
- CActiveXView::AttachPort(Boolean inHasPort)
- {
- if (inHasPort)
- {
- LView *theView;
-
- if (mPendingViewsP)
- {
- for (ArrayIndexT i = 1; mPendingViewsP->FetchItemAt(i, (void*)&theView); i++)
- UpdateDrawingContext(theView, AddContext);
- delete mPendingViewsP;
- mPendingViewsP = NULL;
- }
- else
- for (ArrayIndexT i = 1; mViewArrayP->FetchItemAt(i, (void*)&theView); i++)
- UpdateDrawingContext(theView, AddContext);
-
- UpdateDrawingContext(mActiveView, ActivateContext);
- }
- else
- {
- LView *theView;
-
- if (!mPendingViewsP)
- mPendingViewsP = new LArray(sizeof(LView *));
-
- for (ArrayIndexT i = 1; mViewArrayP->FetchItemAt(i, (void*)&theView); i++)
- mPendingViewsP->InsertItemsAt(1, i, (void*)&theView);
- }
- }
-
-
- #pragma mark === CActiveXView::LView ===
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::LView::Click
- // ---------------------------------------------------------------------------
- // Log self as the active draw context, and pass through the click
-
- void
- CActiveXView::Click(SMouseDownEvent &inMouseDown)
- {
- LView *PrevActiveView = mActiveView;
-
- mActiveView = this;
-
- if (PrevActiveView != mActiveView)
- {
- if (PrevActiveView)
- UpdateDrawingContext(PrevActiveView, DeactivateContext);
- UpdateDrawingContext(mActiveView, ActivateContext);
- }
-
- HandleClick(inMouseDown);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::LView::ResizeFrameBy
- // ---------------------------------------------------------------------------
- // Log self as the active draw context, and pass through the click
-
- void
- CActiveXView::ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh)
- {
- mContextDirty = true;
- LView::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::LView::MoveBy
- // ---------------------------------------------------------------------------
- // Log self as the active draw context, and pass through the click
-
- void
- CActiveXView::MoveBy(Int32 inHorizDelta, Int32 inVertDelta, Boolean inRefresh)
- {
- mContextDirty = true;
- LView::MoveBy(inHorizDelta, inVertDelta, inRefresh);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::LView::AdaptToNewSurroundings
- // ---------------------------------------------------------------------------
- // Log self as the active draw context, and pass through the click
-
- void
- CActiveXView::AdaptToNewSurroundings(void)
- {
- mContextDirty = true;
- LView::AdaptToNewSurroundings();
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::LView::AdaptToSuperFrameSize
- // ---------------------------------------------------------------------------
- // Log self as the active draw context, and pass through the click
-
- void
- CActiveXView::AdaptToSuperFrameSize(Int32 inSurrWidthDelta, Int32 inSurrHeightDelta, Boolean inRefresh)
- {
- mContextDirty = true;
- LView::AdaptToSuperFrameSize(inSurrWidthDelta, inSurrHeightDelta, inRefresh);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::LView::ScrollImageBy
- // ---------------------------------------------------------------------------
- // Log self as the active draw context, and pass through the click
-
- void
- CActiveXView::ScrollImageBy(Int32 inLeftDelta, Int32 inTopDelta, Boolean inRefresh)
- {
- mContextDirty = true;
- LView::ScrollImageBy(inLeftDelta, inTopDelta, inRefresh);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::LView::ResizeImageBy
- // ---------------------------------------------------------------------------
- // Log self as the active draw context, and pass through the click
-
- void
- CActiveXView::ResizeImageBy(Int32 inWidthDelta, Int32 inHeightDelta, Boolean inRefresh)
- {
- mContextDirty = true;
- LView::ResizeImageBy(inWidthDelta, inHeightDelta, inRefresh);
- }
-
-
- #pragma mark === CActiveXView::LCommander ===
-
- // ---------------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------------
-
- void
- CActiveXView::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName )
- {
- if ( inCommand == cmd_Insert)
- outEnabled = true;
- else
- LCommander::FindCommandStatus( inCommand, outEnabled, outUsesMark, outMark, outName );
- }
-
-
- // ---------------------------------------------------------------------------------
- // • CActiveXView::ObeyCommand
- // ---------------------------------------------------------------------------------
-
- Boolean
- CActiveXView::ObeyCommand(CommandT inCommand, void *ioParam)
- {
- #pragma unused (ioParam)
- Boolean cmdHandled = false;
-
- if (inCommand == cmd_Insert)
- {
- StandardFileReply Reply;
- SFTypeList TypeList = { 'shlb' };
-
- ::StandardGetFile(NULL, 1, TypeList, &Reply);
- if (Reply.sfGood)
- {
- if (mControlP)
- RemoveControl();
- InstantiateControl(&Reply.sfFile);
- }
- cmdHandled = true;
- }
- else
- cmdHandled = LCommander::ObeyCommand(inCommand, ioParam);
-
- return cmdHandled;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::BeTarget
- // ---------------------------------------------------------------------------
- // ActiveX view is becoming the Target
-
- void
- CActiveXView::BeTarget()
- {
- if (!mInRequestFocus && mControlP)
- {
- // if the app has gotten so far as to make us the target then there is a window
- if (mPendingViewsP)
- AttachPort(true);
-
- this->RequestFocus( true, KeyboardFocus );
- if (SetFocus(TakeNextCommand, KeyboardFocus) != S_OK)
- {
- LCommander *NewTarget = GetLatentSub();
- this->RequestFocus( false, KeyboardFocus );
- if (NewTarget)
- SwitchTarget(NewTarget);
- }
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::DontBeTarget
- // ---------------------------------------------------------------------------
- // TextEdit is no longer the Target
- //
- // Remove TextEdit from IdleQueue
-
- void
- CActiveXView::DontBeTarget()
- {
- if (!mInRequestFocus)
- {
- this->SetFocus(ReleaseCommand, KeyboardFocus);
- this->RequestFocus( false, KeyboardFocus );
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::HandleKeyPress
- // ---------------------------------------------------------------------------
- // Pass key events to Active X
-
- Boolean
- CActiveXView::HandleKeyPress(const EventRecord& inKeyEvent)
- {
- if (mControlP)
- {
- // this isn't really what tab would mean, cycle through the different
- // contexts, it should really advance the keyboard focus, but I needed
- // a way to test the activate/deactivate code which didn't move the
- // selection point in the text edit control
- if ((inKeyEvent.message & charCodeMask) == '\t')
- {
- ArrayIndexT ActiveViewIndex;
- LView *PrevActiveView = mActiveView;
-
- ActiveViewIndex = mViewArrayP->FetchIndexOf((void*)&PrevActiveView) + 1;
-
- if (!mViewArrayP->FetchItemAt(ActiveViewIndex, (void*)&mActiveView))
- mViewArrayP->FetchItemAt(1, (void*)&mActiveView);
-
- if (PrevActiveView != mActiveView)
- {
- if (PrevActiveView)
- UpdateDrawingContext(PrevActiveView, DeactivateContext);
- UpdateDrawingContext(mActiveView, ActivateContext);
- }
-
- return true;
- }
- else
- {
- KeyEventType theKeyET;
- Point theLocation = inKeyEvent.where;
-
- ::GlobalToLocal(&theLocation);
-
- if (inKeyEvent.what == autoKey)
- theKeyET = AutoKey;
- else
- theKeyET = KeyDown;
-
- return mControlP->DoKey(theKeyET, (inKeyEvent.message & charCodeMask), (EventRecord*) &inKeyEvent);
- }
- }
- else
- return false;
- }
-
-
- #pragma mark === CActiveXView::LDragAndDrop ===
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::LDragAndDrop::ItemIsAcceptable
- // ---------------------------------------------------------------------------
- // tell the control about a draw context change
-
- Boolean
- CActiveXView::ItemIsAcceptable( DragReference inDragRef, ItemReference inItemRef )
- {
- FlavorFlags theFlags;
- if (::GetFlavorFlags( inDragRef, inItemRef, flavorTypeHFS, &theFlags) == noErr)
- {
- HFSFlavor FSData;
- Size DataSize = sizeof(HFSFlavor);
-
- if (::GetFlavorData( inDragRef, inItemRef, flavorTypeHFS, &FSData, &DataSize, 0L) == noErr
- && FSData.fileType == 'shlb' && FSData.fileCreator == 'cfmg')
- return true;
- }
-
- return false;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXView::LDragAndDrop::ReceiveDragItem
- // ---------------------------------------------------------------------------
- // tell the control about a draw context change
-
- void
- CActiveXView::ReceiveDragItem( DragReference inDragRef, DragAttributes,
- ItemReference inItemRef, Rect &)
- {
- HFSFlavor FSData;
- Size DataSize = sizeof(HFSFlavor);
-
- if (::GetFlavorData( inDragRef, inItemRef, flavorTypeHFS, &FSData, &DataSize, 0L ) == noErr)
- {
- if (mControlP)
- RemoveControl();
- InstantiateControl(&FSData.fileSpec);
- }
- }
-
-
- #pragma mark === CActiveXView::CBaseSite::IContainerSite ===
-
-
- // ---------------------------------------------------------------------------------
- // • CActiveXView::CBaseSite::IContainerSite::AcquireContextByID
- // ---------------------------------------------------------------------------------
-
- STDMETHODIMP
- CActiveXView::AcquireContext(Uint32 inContextID, DrawContext* outContext)
- {
- LView *theDrawView;
-
- theDrawView = GetDrawingViewFromID(inContextID);
-
- return AcquireContext(theDrawView, outContext);
- }
-
-
- // ---------------------------------------------------------------------------------
- // • CActiveXView::CBaseSite::IContainerSite::ReleaseContext
- // ---------------------------------------------------------------------------------
-
- STDMETHODIMP
- CActiveXView::ReleaseContext(DrawContext* inContext)
- {
- ErrorCode Result = CXSite::ReleaseContext(inContext);
- LView::OutOfFocus(NULL);
- return Result;
- }
-
-
- // ---------------------------------------------------------------------------------
- // • CActiveXView::CBaseSite::IContainerSite::RequestFocus
- // ---------------------------------------------------------------------------------
-
- STDMETHODIMP
- CActiveXView::RequestFocus (Boolean8 inAcquire, FocusSet inFocus)
- {
- // Pass this on to the document
- mInRequestFocus = true;
- mDocumentP->RequestFocus(this, inAcquire, inFocus);
- mInRequestFocus = false;
-
- return S_OK;
- }
-
-
- // ---------------------------------------------------------------------------------
- // • CActiveXView::CBaseSite::IContainerSite::RequestSizeChange
- // ---------------------------------------------------------------------------------
-
- STDMETHODIMP
- CActiveXView::RequestSizeChange(PlatformPoint* ioSize)
- {
- ArrayIndexT i = 1;
- ErrorCode Result = S_OK;
- LView* ControlView;
-
- while (mViewArrayP->FetchItemAt(i++, &ControlView))
- ControlView->ResizeImageTo(ioSize->h, ioSize->v, false);
-
- return Result;
- }
-
-
- // ---------------------------------------------------------------------------------
- // • CActiveXView::CBaseSite::IContainerSite::SetIdleTime
- // ---------------------------------------------------------------------------------
-
- STDMETHODIMP
- CActiveXView::SetIdleTime (Int32 WaitTicks, Uint32 IdleRefCon)
- {
- ErrorCode Result = CXSite::SetIdleTime(WaitTicks, IdleRefCon);
- CActiveXPeriodical::UpdatePeriodical();
- return Result;
- }
-
-
- #pragma mark === CActiveXAttachment ===
-
- // ---------------------------------------------------------------------------
- // • CActiveXAttachment
- // ---------------------------------------------------------------------------
- // Constructor for ActiveX Attachment
-
-
- CActiveXAttachment::CActiveXAttachment( CActiveXView *inActiveXView )
- : LAttachment( msg_Event ), mActiveXView( inActiveXView )
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXAttachment::~CActivevXAttachment
- // ---------------------------------------------------------------------------
- // Destructor for ActiveX Attachment
-
- CActiveXAttachment::~CActiveXAttachment()
- {
- if (mOwnerHost)
- mOwnerHost->RemoveAttachment(this);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CActiveXAttachment::ExecuteSelf
- // ---------------------------------------------------------------------------
- // Actually do the attachment thing
-
- void CActiveXAttachment::ExecuteSelf( MessageT inMessage, void *ioParam )
- {
- Boolean Remove = false;
-
- mExecuteHost = true;
-
- if (inMessage == msg_Event)
- mActiveXView->DoEvent((EventRecord *)ioParam, &mExecuteHost, &Remove);
-
- if (Remove)
- mOwnerHost->RemoveAttachment(this);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CToPString [ static ]
- // ---------------------------------------------------------------------------
- // convert a c string to a pascal string
-
- void CToPString(Char8* CPtr, StringPtr PStr)
- {
- Char8* p1 = CPtr;
- Char8* p2 = (Char8*) PStr + 1;
- Int16 i = 255;
-
- while (i-- && (*p2++ = *p1++) != 0)
- ;
-
- *PStr = p1 - CPtr - 1;
- }
-